$(function(){

	var postForm = $('#post_form'),
		postType = $('#post_type'),
		postTitle = $('#post_title'),
		postContent = $('#post_content'),
		postBtn = $('#post_btn'),
		errMsg = $('#err_msg')


		postBtn.on('click',function(){
			if(postType.val() == 0){
				addErr(postType.attr('id'),'请选择类别')
				return 

			}

			if(postTitle.val() == ''){

				addErr(postTitle.attr('id'),'标题不能为空')
				return

			}

			if(postTitle.val().length <10 || postTitle.val().length>30){

				addErr(postTitle.attr('id'),'标题字数超出范围')
				return
			}


			if(postContent.val() == ''){

				addErr(postContent.attr('id'),'内容不能为空')
				return

			}


			postForm.submit()

		})

		postContent.on('keyup keydown',function(){

			console.log($(this).val())


		})

		var items = [postType,postTitle,postContent]



		items.forEach(function(item,key){

			item.on('focus',function(){

			clearErr(item.attr('id'))

		})

		})




		



		function addErr(id,text){

			errMsg.text(text).show()
			$('label[for='+id+']').addClass("err")
			postBtn.blur()
		}

		function clearErr(id){

			errMsg.hide()

			if($('label[for='+id+']').hasClass("err")){

				$('label[for='+id+']').removeClass("err")

			}

		}



})